import { FormValues as UserInfo } from '@/pages/Login'
import { FormValues as UserInfoRegister } from '@/pages/Register'
import { FormValues as UserInfoForget } from '@/pages/Forget'
const sotre = {
  state: {
    userInfo: JSON.parse(localStorage.getItem('userInfo') || '{}') as UserInfo,
    userInfoRegister: JSON.parse(
      localStorage.getItem('userInfoRegister') || '{}'
    ) as UserInfoRegister,
    userInfoForget: JSON.parse(
      localStorage.getItem('userInfoForget') || '{}'
    ) as UserInfoForget
  },
  actions: {
    saveUser(
      newState: { userInfo: UserInfo },
      action: { type: string; payload: UserInfo }
    ) {
      newState.userInfo = action.payload
      localStorage.setItem('userInfo', JSON.stringify(action.payload))
    },
    saveUserRegister(
      newState: { userInfoRegister: UserInfoRegister },
      action: { type: string; payload: UserInfoRegister }
    ) {
      newState.userInfoRegister = action.payload
      localStorage.setItem('userInfoRegister', JSON.stringify(action.payload))
    },
    saveUserForget(
      newState: { userInfoForget: UserInfoForget },
      action: { type: string; payload: UserInfoForget }
    ) {
      newState.userInfoForget = action.payload
      localStorage.setItem('userInfoForget', JSON.stringify(action.payload))
    }
  },
  actionNames: {}
}

const actionNames = {}
for (const key in sotre.actions) {
  actionNames[key] = key
}
sotre.actionNames = actionNames

export default sotre
